package A1;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

/**
 * Created by IntelliJ IDEA.
 * User: Sarah
 * Date: 17/08/2011
 * Time: 2:40:21 PM
 * To change this template use File | Settings | File Templates.
 */

public class elevatorShaft extends JPanel {

    int numOfFloor, heightOfFloor, floor = 1, relativeHeight = 0, currentHeight;
    int movement = 0, widthUpBound, widthLowBound = 1;

    /**
     * Sets the number of floors to the user's input
     */
    public elevatorShaft(int numOfFloor) {
        this.numOfFloor = numOfFloor;
    }

    /**
     * Re paints the elevator as it moves and the doors open and close
     */
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        widthUpBound = getWidth() / 2 - 10;

        int YPoint = getHeight() * (numOfFloor - floor) / numOfFloor + relativeHeight;
        heightOfFloor = getHeight() / numOfFloor;
        currentHeight = (floor - 1) * heightOfFloor - relativeHeight;

        g.setColor(Color.lightGray);
        g.fillRect(3, YPoint, getWidth() - 2, heightOfFloor - 1);

        g.setColor(Color.DARK_GRAY);
        g.fillRect(3, YPoint, getWidth() / 2 - 3 - movement, heightOfFloor);
        g.fillRect(getWidth() / 2 + 3 + movement, YPoint, getWidth() / 2 - 5 - movement, heightOfFloor);

        g.setColor(Color.BLUE);
        g.draw3DRect(1, 1, getWidth() - 2, getHeight() - 2, true);
    }

    /**
     * Re paints the elevator when it moves up the elevator shaft
     */
    void moveUp() {
        relativeHeight--;
        repaint();
    }

    /**
     * Re paints the elevator when it moves down the elevator shaft
     */
    void moveDown() {
        relativeHeight++;
        repaint();
    }

    /**
     * Re paints the elevator when the close door button is pressed
     */
    void closeGate() {
        movement--;
        repaint();
    }

    /**
     * Re paints the elevator when the open door button is pressed
     */
    void openGate() {
        movement++;
        repaint();
	 }
}